// pages/order/info/index.js
const App=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title:'',
    canteenId: '',
    shoucang: App.Imges.shoucang,
    xin: App.Imges.xin,
    list:{},
    canteenList: [],
    limit: 20,
    offset: 1,
    total: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.param) {
      let param = JSON.parse(options.param);
      this.getList(param);
      this.setData({
        param: options.param,
        canteenId: param.id
      })
      this.getCanteenList();
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.offset < (this.data.total / this.data.limit)) {
      this.setData({
        offset: this.data.offset + 1
      })
      this.getCanteenList();
    }
  },
  onPullDownRefresh: function () {
    this.getList(this.data.param);
    this.setData({
      offset: 1
    })
    this.getCanteenList();
  },

  getCanteenList() {
    let url = 'mp/dishes/evaluate';
    let param = {
      dishes_list_id: this.data.canteenId,
      limit: this.data.limit,
      offset: this.data.offset
    };
    App.ajax(url, 'GET', param).then(res => {
      if (res.status === 10000) {
        if (this.data.offset === 1) {
          this.setData({
            canteenList: res.data.rows,
            total: res.data.count
          })  
        } else {
          let all = JSON.parse(JSON.stringify(this.data.canteenList));
          all = all.concat(res.data.rows);
          this.setData({
            canteenList: all,
            total: res.data.count
          })
        }
      } else {
        App.prompts(res.msg)
      }
    }).catch(err => {
      console.log(err)
    })
  },
  getList(param) {
    let url = 'mp/dishes/detail';
    App.ajax(url, 'GET', param).then(res => {
      if (res.status === 10000) {
        this.setData({
          list: res.data
        })
      } else {
        App.prompts(res.msg)
      }
    }).catch(err => {
      console.log(err)
    })
  },
  upper(e) {
    console.log('滚动到顶部/左边时触发',e)
  },
  lower(e) {
    console.log('滚动到底部/右边时触发', e)
  }
})